package com.xpgk.mvc.todayMeasure;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.codec.binary.Base64;
import org.w3c.dom.css.CSSUnknownRule;

import com.jfinal.config.Constants;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.xpgk.annotation.Service;
import com.xpgk.constant.ConstantRender;
import com.xpgk.dto.RenderBean;
import com.xpgk.mvc.base.BaseService;
import com.xpgk.mvc.bentryRegister.BentryRegisterService;
import com.xpgk.mvc.bentryRegister.Customer;
import com.xpgk.mvc.bentryRegister.CustomerAgreement;
import com.xpgk.mvc.bentryRegister.CustomerDetail;
import com.xpgk.mvc.bloseWeight.DelWeiTargetSum;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.user.User;
import com.xpgk.tools.ToolDateTime;
import com.xpgk.tools.ToolRandoms;
import com.xpgk.tools.security.ToolPbkdf2;

@Service(name = TodayMeasureServices.serviceName)
public class TodayMeasureServices  extends  BaseService{
	
	public static final String serviceName = "todayMeasureServices";	
		
	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(TodayMeasureServices.class);

		
		/*
		 * 今日测算查询
		 */
		public List<Record> todaymeasure(String organids, String todaydate) {
			String sql =getSqlMy("sb.todaymeasure.todaymeasure") ;
			List<Record> result = Db.find(sql,organids,todaydate);
			String visitsql = "SELECT count(*) AS count, visitType FROM sb_customer_scallvisit WHERE customerids=? AND organIds=? GROUP BY visitType";
			
			for(Record r : result){
				List<Record> visitfind = Db.find(visitsql,r.get("ids").toString(),organids);
				for(Record f : visitfind){
					String visittype = f.get("visittype").toString();
					if(visittype.equals("1")){
						r.set("callvisitcount", f.get("count").toString());
					}else if(visittype.equals("2")){
						r.set("toshopvisitcount", f.get("count").toString());
					}
				}
			}
			return result;
		}
		
}
